import re

# 精准匹配
print('-'*20,'精准匹配','-'*20)
m = re.match('test','test python regex')
print(m.group())

# 特殊字符匹配
print('-'*20,'特殊字符匹配','-'*20)
m1 = re.match('\$test','$test python regex')
print(m1.group())

# 匹配任意字符
print('-'*20,'匹配任意字符 . ','-'*20)
m2 = re.match('.', 'test python regex')
print(m2.group())

# [] 匹配[]中列举字符
print('-'*20,'[] 匹配[]中列举字符','-'*20)
m3 = re.match('[a-z]','test python regex')
print(m3.group())

# \d 匹配任意数字
print('-'*20,'\d 匹配任意数字','-'*20)
m4 = re.match('python2','python2 regex')
print(m4.group())
m5 = re.match('python\d','python2 regex')
print(m5.group())

# \D 匹配任意非数字
print('-'*20,'\D 匹配任意非数字','-'*20)
m6 = re.match('pytho\D','python2 regex')
print(m6.group())

# \s 匹配任意空白字符
print('-'*20,'\s 匹配任意空白字符','-'*20)
m7 = re.match('test\s','test python regex')
print(repr(m7.group()))

# \S 匹配任意非空白字符
print('-'*20,'\S 匹配任意非空白字符','-'*20)
m8 = re.match('tes\S\spython','test python regex')
print(m8.group())

# \w 匹配任意字母数字字符
print('-'*20,'\w 匹配任意字母数字字符','-'*20)
m9 = re.match('\w','test python regex')
print(m9.group())

# \W 匹配任意非字母数字字符
print('-'*20,'\W 匹配任意非字母数字字符','-'*20)
m10 = re.match('\W','#test python regex')
print(m10.group())